// Vue对象
var vm_servicedListTable = new Vue({
    el: '#servicedListTable',
    data: {
        servicedList: null
    },
    methods: {
        update: function () {
            this.$http.get("chateds").then(function (value) {
                this.servicedList = value.body;
            });
        }
    }
});

/**
 * 功能盒子
 */
var vm_funcBox = new Vue({
    el: '#funcBox',
    methods: {
        reqService: function () {
            this.$http.get("reqService").then(function (value) {
                alert("请求成功！")
            }, function (reason) {
                // 失败请求
                alert(reason.body);
            })
        },
        cutChat: function () {
            this.$http.put("chat").then(function (value) {
                alert(value.body)
            },function (reason) { alert(reason.body) })
        },
        endChat: function () {
            var score = prompt('请输入评分');
            this.$http.delete("chat", {params : {score: score}}).then(function (value) {
                alert("完成评分");
                window.location.reload();
            },function (reason) { alert(reason.body) })
        }
    }
});

/**
 * 聊天记录窗口
 */
var vm_msgListTable = new Vue({
    el: '#msgListTable',
    data: {
        msgList: [],
        sendMsg: {}
    },
    methods: {
        updateMsgList: function () {
            this.$http.get("msgList").then(function (value) {
                // 成功
                this.msgList = value.body;
            }, function (reason) {
                // 400
                console.log(reason.body);
            })
        },
        getNewMsg: function () {
            this.$http.get("newMsg").then(function (value) {
                this.msgList.push(value.body);
            })
        },
        fsendMsg: function () {
            var msg = {};
            msg.value = this.sendMsg.value;
            msg.time = new Date();
            msg.type = 1;
            this.$http.post("msg", msg).then(function (value) { this.msgList.push(msg); },
                function (reason) { alert(reason.body) });
        }
    }
})
// ---------初始化区
vm_msgListTable.updateMsgList();
// --------- 心跳区
setInterval(vm_msgListTable.getNewMsg, 1000);

// --------- 循环获取数据区
vm_servicedListTable.update();
setInterval(vm_servicedListTable.update, 30 * 1000);
// setInterval(vm_msgListTable.updateMsgList, 1000);

// 可以更改逻辑，用setTimeout()，以减轻服务器压力
// http://www.runoob.com/jsref/met-win-setinterval.html






























